﻿#region Header

/*
Behavioral Rating of Dancing Human Crowds based on Motion Patterns
By

Pascal Hauser 
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

and

Raphael Gfeller
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

*/

#endregion

#region Usings

using System;
using Emgu.CV;
using Emgu.CV.Structure;
using paravili.Services;
using Sebarf.Services.Interfaces;

#endregion

namespace paravili.Steps {
	/// <summary>
	/// applies the smooth gaussian algorithm on the given image
	/// </summary>
	public class SmoothGaussian : ProcessStepWithMeasurement<Image<Bgr, Byte>> {
		#region Public Properties

		[ConfigurabelBooleanValue(Name = "SmoothGaussian")]
		public bool IsEnable { get; set; }

		[ConfigurableNumericValue(Name = "Kernel Size", RangeFrom = 1, RangeTo = 37)]
		public int KernelSize { get; set; }

		[ServiceRequest(IsOptional = true)]
		public IImageProviderService ImageProviderService { get; set; }

		[ConfigurabelStringValue(Name = "ImageProviderId")]
		public String ImageProviderId { get; set; }

		[ConfigurabelBooleanValue(Name = "ForwardImageToImageProvider")]
		public bool ForwardImageToImageProvider { get; set; }

		#endregion

		#region Public Methods

		public SmoothGaussian() {
			KernelSize = 5;
			ImageProviderId = "SmoothGaussian.ImageData";
			ForwardImageToImageProvider = false;
		}

		protected override Image<Bgr, byte> OnProcess(Image<Bgr, byte> toProcess) {
			Image<Bgr, byte> toReturn = toProcess;
			if (IsEnable) {
				if (KernelSize % 2 == 0) {
					KernelSize++;
				}
				toReturn = toProcess.SmoothGaussian(KernelSize);
			}
			if (ForwardImageToImageProvider) {
				ImageProviderService.SetImage(ImageProviderId, toReturn.Convert<Lab, Byte>());
			}
			return toReturn;
		}

		#endregion
	}
}